package com.ax.base.drugadministration.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ax.base.drugadministration.domain.BaseDrugManager;

@Mapper
public interface BaseDrugManagerMapper {
    int deleteByPrimaryKey(Long drugManagerId);

    int insert(BaseDrugManager record);
    @Insert("<script>"+
            "insert into base_drug_manager (Drug_Manager_ID, Drug_Manager_Name, Drug_Dep_ID,"+
            "Drug_Dep_Name, Post, Empno,Person_ID, Sex, Birth,Entry_Time, Phone, Address,Remarks, create_date, update_date,Flag)"+
            "values (#{drugManagerId}, #{drugManagerName}, #{drugDepId},"+ 
      	    "#{drugDepName}, #{post}, #{empno},"+ 
      	    "#{personId}, #{sex}, #{birth},"+ 
      	    "#{entryTime}, #{phone}, #{address},"+ 
      	    "#{remarks}, NOW(), NOW(),"+
      	    "#{flag})"+
      	    "</script>")
    int insertSelective(BaseDrugManager record);

    @Select("<script>"+
    "select Drug_Manager_ID, Drug_Manager_Name, Drug_Dep_ID, Drug_Dep_Name, Post, Empno, Person_ID,"+ 
    "Sex, Birth, Entry_Time, Phone, Address, Remarks, create_date, update_date, Flag "+
    "from base_drug_manager " +
    "where Drug_Manager_ID = #{drugManagerId}" +
    "</script>")
    BaseDrugManager selectByPrimaryKey(Long drugManagerId);

    @Update("<script>"+
    "update base_drug_manager"+
    "<set>"+
    "<if test=\"drugManagerName != null and drugManagerName != ''\">"+ "Drug_Manager_Name = #{drugManagerName}, " + "</if>" + 
    "<if test=\"drugDepId != null\">"+ "Drug_Dep_ID = #{drugDepId}, " + "</if>" + 
    "<if test=\"drugDepName != null and drugDepName != ''\">"+ "Drug_Dep_Name = #{drugDepName}, " + "</if>" + 
    "<if test=\"post != null\">"+ "Post = #{post}, " + "</if>" + 
    "<if test=\"empno != null and empno != ''\">"+ "Empno = #{empno}, " + "</if>" +
    "<if test=\"personId != null\">"+ "Person_ID = #{personId}, " + "</if>" + 
    "<if test=\"sex != null and sex != ''\">"+ "Sex = #{sex}, " + "</if>" + 
    "<if test=\"birth != null\">"+ "Birth = #{birth}, " + "</if>" + 
    "<if test=\"entryTime != null\">"+ "Entry_Time = #{entryTime}, " + "</if>" + 
    "<if test=\"phone != null and phone != ''\">"+ "Phone = #{phone}, " + "</if>" +
    "<if test=\"address != null and address != ''\">"+ "Address = #{address}, " + "</if>" +
    "<if test=\"remarks != null and remarks != ''\">"+ "Remarks = #{remarks}, " + "</if>" +
    "create_date = NOW()," +
    "update_date = NOW()," +
    "<if test=\"flag != null\">"+ "Flag = #{flag}, " + "</if>" +
    "</set>"+
    "where Drug_Manager_ID = #{drugManagerId}"+
    "</script>")
    int updateByPrimaryKeySelective(BaseDrugManager baseDrugManager);

    int updateByPrimaryKey(BaseDrugManager record);
    
    /**
	 * 药监查询(模块:药监人员)
	 * 
	 * @param Map<String, Object> map
	 *           
	 * @return PageUtils
	 */
     @Select("<script>"+
	    "select base_drug_manager.Drug_Manager_ID drugManagerId, base_drug_manager.Drug_Manager_Name drugManagerName,"+ 
    	"base_drug_manager.Drug_Dep_ID drugDepId, base_drug_manager.Drug_Dep_Name drugdepName, base_drug_manager.Post post, base_drug_manager.Empno empno, base_drug_manager.Person_ID personId,"+ 
        "base_drug_manager.Sex sex, base_drug_manager.Birth birth, base_drug_manager.Entry_Time entryTime,"+
    	"base_drug_manager.Phone phone, base_drug_manager.Address address, base_drug_manager.Remarks remarks,"+ 
        "base_drug_manager.create_date creatDate, base_drug_manager.update_date updateDate, base_drug_manager.Flag flag,"+ 
        "base_drug_dep.Drug_Dep_ID drugDepId,base_drug_dep.Drug_Dep_Code drugDepCode,base_drug_dep.Drug_Dep_Name drugDepName "+
        "from base_drug_manager "+
        "left join base_drug_dep on base_drug_manager.Drug_Dep_ID = base_drug_dep.Drug_Dep_ID"+
        "<where>"+ 
     	"<if test=\"drugManagerId != null\">"+ "and base_drug_manager.Drug_Manager_ID = #{drugManagerId} " + "</if>" +
     	"<if test=\"drugDepId != null\">"+ "and base_drug_dep.Drug_Dep_ID = #{drugDepId} " + "</if>" +
     	"</where>"+
     	/*"<if test=\"offset != null and limit != null\">"+
		"limit #{offset}, #{limit}" + 
		"</if>"+*/
     	"</script>")
     List<BaseDrugManager> queryDrugAdministrationManagerMapper(Map<String, Object> params);
     
     
     /**
 	 * 药监总计分页(模块:药监人员)
 	 * 
 	 * @param Map<String, Object> map
 	 *           
 	 * @return Integer
 	 */
     @Select("<script>"+
	    "select count(0) "+
        "from base_drug_manager "+
        "left join base_drug_dep on base_drug_manager.Drug_Dep_ID = base_drug_dep.Drug_Dep_ID"+
        "<where>"+ 
     	"<if test=\"drugManagerId != null\">"+ "and base_drug_manager.Drug_Manager_ID = #{drugManagerId} " + "</if>" +
     	"<if test=\"drugDepId != null\">"+ "and base_drug_dep.Drug_Dep_ID = #{drugDepId} " + "</if>" +
     	"</where>"+
     	"</script>")
     Integer count(Map<String,Object> params);
     
     
     /**
 	 * 编号是否重复(新增)
 	 * 
 	 * @param String parameter
 	 *         
 	 * @return boolean
 	 */
     @Select("<script>"+
	    "select base_drug_manager.Drug_Manager_ID drugManagerId, base_drug_manager.Drug_Manager_Name drugManagerName,"+ 
    	"base_drug_manager.Drug_Dep_ID drugDepId, base_drug_manager.Drug_Dep_Name drugdepName, base_drug_manager.Post post, base_drug_manager.Empno empno, base_drug_manager.Person_ID personId,"+ 
        "base_drug_manager.Sex sex, base_drug_manager.Birth birth, base_drug_manager.Entry_Time entryTime,"+
    	"base_drug_manager.Phone phone, base_drug_manager.Address address, base_drug_manager.Remarks remarks,"+ 
        "base_drug_manager.create_date creatDate, base_drug_manager.update_date updateDate, base_drug_manager.Flag flag,"+ 
        "base_drug_dep.Drug_Dep_ID drugDepId,base_drug_dep.Drug_Dep_Code drugDepCode,base_drug_dep.Drug_Dep_Name drugDepName "+
        "from base_drug_manager "+
        "left join base_drug_dep on base_drug_manager.Drug_Dep_ID = base_drug_dep.Drug_Dep_ID "+
        "<where>"+ 
     	"<if test=\"empno != null\">"+ "and base_drug_manager.Empno = #{empno} " + "</if>" +
     	"<if test=\"personId != null\">"+ "and base_drug_manager.Person_ID = #{personId} " + "</if>" +
     	"<if test=\"phone != null\">"+ "and base_drug_manager.Phone = #{phone} " + "</if>" +
     	"</where>"+
     	"</script>")
     List<BaseDrugManager> validateMapper(Map<String,Object> params);
     
     
     /**
 	 * 是否重复(修改)
 	 * 
 	 * @param String parameter
 	 *         
 	 * @return boolean
 	 */
     @Select("<script>"+
	    "select base_drug_manager.Drug_Manager_ID drugManagerId, base_drug_manager.Drug_Manager_Name drugManagerName,"+ 
    	"base_drug_manager.Drug_Dep_ID drugDepId, base_drug_manager.Drug_Dep_Name drugdepName, base_drug_manager.Post post, base_drug_manager.Empno empno, base_drug_manager.Person_ID personId,"+ 
        "base_drug_manager.Sex sex, base_drug_manager.Birth birth, base_drug_manager.Entry_Time entryTime,"+
    	"base_drug_manager.Phone phone, base_drug_manager.Address address, base_drug_manager.Remarks remarks,"+ 
        "base_drug_manager.create_date creatDate, base_drug_manager.update_date updateDate, base_drug_manager.Flag flag,"+ 
        "base_drug_dep.Drug_Dep_ID drugDepId,base_drug_dep.Drug_Dep_Code drugDepCode,base_drug_dep.Drug_Dep_Name drugDepName "+
        "from base_drug_manager "+
        "left join base_drug_dep on base_drug_manager.Drug_Dep_ID = base_drug_dep.Drug_Dep_ID "+
        "<where>"+ 
        "<if test=\"drugManagerId != null\">"+ "and base_drug_manager.Drug_Manager_ID != #{drugManagerId} " + "</if>" +
     	"<if test=\"empno != null\">"+ "and base_drug_manager.Empno = #{empno} " + "</if>" +
     	"<if test=\"personId != null\">"+ "and base_drug_manager.Person_ID = #{personId} " + "</if>" +
     	"<if test=\"phone != null\">"+ "and base_drug_manager.Phone = #{phone} " + "</if>" +
     	"</where>"+
     	"</script>")
     List<BaseDrugManager> updatevalidateMapper(Map<String,Object> params);
}